
package cz.czu.pef.DataModelling.domainObjects;

import java.util.*;

public class Company extends IdObjectImpl implements IdObject
{
  private static final long serialVersionUID = 4863818897776452723L;

  private String name;
	private String ico;
	private String dic;
	private Address baseAddress;
	private Set<Address> branchAddresses;

	/*
	 * Relations
	 */
	private Set<Employee> employees;
	private Set<ExternalWorker> extWorkers;
	private Set<Machinery> machinery;

	public Company()
	{
		super();
	}

	public Company(final String name, final String ico, final String dic)
	{
		setName(name);
		setIco(ico);
		setDic(dic);
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getIco()
	{
		return ico;
	}

	public void setIco(String ico)
	{
		this.ico = ico;
	}

	public String getDic()
	{
		return dic;
	}

	public void setDic(String dic)
	{
		this.dic = dic;
	}
	
	public Address getBaseAddress()
	{
		return baseAddress;
	}

	public void setBaseAddress(Address baseAddress)
	{
		this.baseAddress = baseAddress;
	}

	public Set<Address> getBranchAddresses()
	{
		return branchAddresses;
	}

	public List<Address> getBranchAddressesAsList()
	{
		return new ArrayList<Address>(getBranchAddresses());
	}

	public void addBranchAddress(Address address)
	{
		if (branchAddresses == null)
			branchAddresses = new HashSet<Address>();
		branchAddresses.add(address);
	}

	public void hireEmployee(Employee employee)
	{
		if (employees == null)
			employees = new HashSet<Employee>();
		employees.add(employee);
	}

	public void hireExternalWorker(ExternalWorker employee)
	{
		if (extWorkers == null)
			extWorkers = new HashSet<ExternalWorker>();
		extWorkers.add(employee);
	}

	public Set<Employee> getEmployees()
	{
		return employees;
	}

	public List<Employee> getEmployeesAsList()
	{
		return new ArrayList<Employee>(getEmployees());
	}

	public Set<ExternalWorker> getExtWorkers()
	{
		return extWorkers;
	}

	public List<ExternalWorker> getExtWorkersAsList()
	{
		return new ArrayList<ExternalWorker>(getExtWorkers());
	}

	public Set<Machinery> getMachinery()
	{
		return machinery;
	}

	public List<Machinery> getMachineryAsList()
	{
		return new ArrayList<Machinery>(getMachinery());
	}

	
  public void setBranchAddresses(Set<Address> branchAddresses)
  {
    this.branchAddresses = branchAddresses;
  }

  
  public void setEmployees(Set<Employee> employees)
  {
    this.employees = employees;
  }

  
  public void setExtWorkers(Set<ExternalWorker> extWorkers)
  {
    this.extWorkers = extWorkers;
  }

  
  public void setMachinery(Set<Machinery> machinery)
  {
    this.machinery = machinery;
  }

  public String toString()
	{
		StringBuilder builder = new StringBuilder();
		builder.append("Company [name=");
		builder.append(getName());
		builder.append(", ico=");
		builder.append(getIco());
		builder.append(", baseAddress=");
		builder.append(getBaseAddress());
		builder.append(", branchAddresses=");
		builder.append(getBranchAddresses());
		builder.append(", employees=");
		builder.append(getEmployees());
		builder.append(", extWorkers=");
		builder.append(getExtWorkers());
		builder.append(", machinery=");
		builder.append(getMachinery());
		builder.append(", toString()=");
		builder.append(super.toString());
		builder.append("]");
		return builder.toString();
	}
}
